// The following example was provided by Jeff Cutsinger // // Spring 2004 // // The goal of the example is to get dynamically allocate // just enough memory for a c-style string for the continence // in the input buffer. #include #include using std::ostrstream; using std::ends; using std::cin; using std::cout; using std::endl; void main() { ostrstream Buffer; cin.get(*Buffer.rdbuf()); Buffer << ends; //adds a null terminator to the end of the internal string Buffer.freeze(); // ensures that the string will not be dealocated when Buffer goes out of scope char* pString = Buffer.str(); cout << pString << endl; delete pString; }